package com.gundam.tools.lint.checks

import com.android.tools.lint.detector.api.*
import com.intellij.psi.PsiMethod
import org.jetbrains.uast.UCallExpression

/**
 * RecyclerView.setLayoutManager
 * @author wpq
 * @version 1.0
 */
@Suppress("UnstableApiUsage")
class RecyclerViewLayoutManagerDetector : Detector(), Detector.UastScanner {

    override fun getApplicableConstructorTypes(): List<String>? {
        return listOf(
                "androidx.recyclerview.widget.LinearLayoutManager",
                "androidx.recyclerview.widget.GridLayoutManager",
                "androidx.recyclerview.widget.StaggeredGridLayoutManager",
                "com.google.android.flexbox.FlexboxLayoutManager")
    }

    override fun visitConstructor(context: JavaContext, node: UCallExpression, constructor: PsiMethod) {
        context.report(ISSUE, node, context.getLocation(node),
                "请使用DKLinearLayoutManager、DKGridLayoutManager、DKStaggeredGridLayoutManager、DKFlexboxLayoutManager")
    }

    companion object {
        @JvmField
        val ISSUE = Issue.create(
                // ID: used in @SuppressLint warnings etc
                "RecyclerView.setLayoutManager",

                // Title -- shown in the IDE's preference dialog, as category headers in the
                // Analysis results window, etc
                "RecyclerView有bug：https://www.jianshu.com/p/8f4afac1cd12",

                // Full explanation of the issue; you can use some markdown markup such as
                // `monospace`, *italic*, and **bold**.
                "使用DKLinearLayoutManager、DKGridLayoutManager等避免bug：https://www.jianshu.com/p/8f4afac1cd12",
                Category.CORRECTNESS,
                6,
                Severity.WARNING,
                Implementation(RecyclerViewLayoutManagerDetector::class.java, Scope.JAVA_FILE_SCOPE))
    }
}